package com.jun.basic.mapper;

import com.jun.basic.domain.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Repository
public class UserMapper {

    private static Map<String, User> userMap = new HashMap<>();

    static {
        userMap.put("caojun", new User(1, "caojun", "123456"));
        userMap.put("tom", new User(1, "tom", "123"));
        userMap.put("xiaod", new User(1, "xiaod", "666"));
    }

    public User login(String username, String pwd) {
        User user = userMap.get(username);
        if (Objects.isNull(user)) {
            return null;
        }
        if (Objects.equals(user.getPwd(), pwd)) {
            return user;
        }
        return null;
    }
}
